﻿
namespace QSHC.QSchedule.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using QSHC.QSchedule.Web.Models;


    // Implements application logic using the QSHCEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class QSHCDomainService : LinqToEntitiesDomainService<QSchedule_EmployeeEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Employees' query.
        public IQueryable<Employee> GetEmployees()
        {
            return this.ObjectContext.Employees.Include("Title")
                                               .Include("Division")
                                               .OrderBy(p => p.FirstName); // Doctor
        }

        public Employee GetEmployeeByEmployeeCode(string employeeCode)
        {
            return this.ObjectContext.Employees.Include("Title").Include("Division").Single(p => p.EmployeeCode == employeeCode);
                                               
        }

        public IQueryable<Employee> GetPhysicians()
        {
            return this.ObjectContext.Employees.Include("Title")
                                               .Include("Division")
                                               .Where(p => p.JobPositionID == 24)
                                               .OrderBy(p => p.FirstName); // Doctor
        }

        public Employee GetPhysicianByEmployeeCode(string employeeCode)
        {
            return this.ObjectContext.Employees.Include("Title")
                                               .Include("Division")
                                               .Where(p => p.JobPositionID == 24) // Doctor
                                               .Single(p => p.EmployeeCode == employeeCode);
        }
    }
}


